/*
2021-11-8
https://ac.nowcoder.com/acm/contest/22551/E
*/
#include<cstring>
#include<iostream>
#include<algorithm>


using namespace std;
int n, x, m;
int T;
int a[105];
int c[105][1002];
int ans;
int f[105][1005];

int main()
{
    cin >> T;
    while (T--)
    {
        memset(f, 0, sizeof f);
        cin >> n >> x >> m;
        for (int i = 0; i < n; i++) cin >> a[i];
        sort(a, a + n);
        int s = 0;
        for (int i = n - 1; i > n - 1 - x; i--)
            s += a[i];
        for (int i = 0; i < m; i++)
            for (int j = 1; j <= s; j++)
                cin >> c[i][j];
        for (int i = 0; i < m; i++)
            for (int j = 0; j <= s; j++)
                for (int k = 0; k <= s; k++)
                {
                    if (j >= k)
                        f[i][j] = max(f[i][j], f[i - 1][j - k] + c[i][k]);
                }
        int ans = 0;
        for (int i = 0; i <= s; i++)
            ans = max(ans, f[m - 1][i]);
        cout << ans << endl;
    }
    return 0;
}



